const {app, BrowserWindow, Menu, ipcMain} =require('electron');//引入electron
const path = require('path')
const handleIPC = require('./handleIPC')
let win;
let windowConfig = {
  width: 1024,
  height: 768,
  webPreferences: {
    webSecurity: false,
    nodeIntegration: true,
    contextIsolation: true,
    preload: path.join(__dirname, "../main/preload.js")
  }
};//窗口配置程序运行窗口的大小
function createWindow(){
  Menu.setApplicationMenu(null);
  win = new BrowserWindow(windowConfig);//创建一个窗口
  //win.loadURL(`file://${path.join(__dirname, "./index.html")}`);//在窗口内要展示的内容index.html 就是打包生成的index.html
  win.loadFile('dist/index.html');
  win.webContents.openDevTools();  //开启调试工具

  handleIPC(win);

  win.on('close',() => {
    //回收BrowserWindow对象
    win = null;
  });
  /*win.on('resize',() => {
    win.reload();
  })*/
}
app.on('ready',createWindow);
app.on('window-all-closed',() => {
  app.quit();
});
app.on('activate',() => {
  if(win == null){
    createWindow();
  }
});
